package com.pig4cloud.pig.demo.Util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by caoxuel on 2020/11/4 11:45
 * @author caoxuel
 */
public final class CheckEmailAndPhoneUtil {

    public final static String CHECK_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    public final static String CHECK_PHONE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}|[0]{1}[0-9]{2,3}-[0-9]{7,8}$";

    /**
     * 校验邮箱格式
     * @param email
     * @return
     */
    public static Boolean checkEmail(String email){
        Pattern regex = Pattern.compile(CHECK_EMAIL);
        Matcher matcher = regex.matcher(email);
        boolean isMatched = matcher.matches();
        return isMatched;
    }

    /**
     * 校验电话格式
     * @param phone
     * @return
     */
    public static Boolean checkPhone(Long phone){
        Pattern pattern=Pattern.compile(CHECK_PHONE);
        Matcher matcher=pattern.matcher(phone.toString());
        return matcher.matches();
    }

}
